/*
 * Copyright (c) 2007, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.graphCombinator;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

import ac.jp.u_tokyo.SyncLib.Mod;
import ac.jp.u_tokyo.SyncLib.NullMod;

public class Variable implements Iterable<Variable.SyncIndexPair>{
    private Object _value = null;
    Object getValue() {
        return _value;
    }
    void setValue(Object value) {
        _value = value;
    }
    
    private Mod _mod = NullMod.INSTANCE;
    Mod getMod() {
        return _mod;
    }
    void setMod(Mod mod) {
        _mod = mod;
    }
    
    private Mod _hmod = NullMod.INSTANCE;
    Mod getHighMod() {
    	return _hmod;
    }
    void setHighMod(Mod mod) {
    	_hmod = mod;
    }
    
    private Collection<SyncIndexPair> _connectedSyncHolders =
        new LinkedList<SyncIndexPair>();
    
    public class SyncIndexPair {
    	private SyncHolder _syncHolder;
    	private int _index;
		public SyncIndexPair(SyncHolder syncHolder, int index)
		{
			super();
			_syncHolder = syncHolder;
			_index = index;
		}
		public SyncHolder getSyncHolder()
		{
			return _syncHolder;
		}
		public int getIndex()
		{
			return _index;
		}
    }
    
    void onConnectedToSyncHolder(SyncHolder sh, int index) {
        _connectedSyncHolders.add(new SyncIndexPair(sh, index));
    }
    
    public Iterator<SyncIndexPair> iterator() {
        return _connectedSyncHolders.iterator();
    }
    
}
